#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : lee

import sys
import os
import logging
import re
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    # import pymel.core as pm
    # import JTK.jmaya.core as jmc
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class DisplayLayersCheck(CheckBase):
    def __init__(self):
        super(DisplayLayersCheck, self).__init__()
        pass

    def get_exist_display_layers(self):
        exist_display_layers = cmds.ls(type="displayLayer")
        unnecessary_display_layers = []
        for layer in exist_display_layers:
            if layer != "defaultLayer":
                unnecessary_display_layers.append(layer)
        return unnecessary_display_layers

    def check(self):
        result_proc = self.get_exist_display_layers()
        if result_proc:
            result_log = u'Error:%s\n' % result_proc
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        try:
            result_proc = self.get_exist_display_layers()
            for layer in result_proc:
                cmds.delete(layer)
            return u'Succeed:没有问题\n'
        except:
            result_proc = self.get_exist_display_layers()
            result_log = u'Error:%s\n清除失败' % result_proc
            return result_log
